<?php
error_reporting(7);
if(!empty($_POST)){
	unset($_POST['sign']);
	$sign = getSign($_POST);
	echo $sign;
	die;
}
function getSign($postData){
	$merchant_key='ch902a57f48446b9a1b5ecb8295ef09b';
    ksort($postData);
    $str = '';
    foreach($postData as $key=>$val){
    	if($val === ''){
    	 continue;
    	}
        $str .= "&".$key."=".$val;
    }
    $str = substr($str,1).$merchant_key;
    return md5($str);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>余额消费测试表单</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
</head>
<script>
	$(function(){
		$('#update').click(function () {
			$postdata = $("form").serialize();
			$.post("balancepay.php", $postdata,
			  function(data){
			    $('input[name=sign]').val(data);
			  });
  		});
	});
</script>
<style>
body {
	font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	color:#555;
}
h1, form, button {
	border: 0;
	margin: 0;
	padding: 0;
}

h1{
	font-size: 1.5em;
	font-weight: bold;
	margin-bottom: 8px;
	}
form {
	margin: 0;
	width: 550px;
	padding: 10px;
}
form input {
	float:left;
	border: 1px solid #ddd;
	padding: 2px 4px;
	width: 350px;
	margin: 4px 10px;
}
form input:hover {
	border: 1px solid #2ca9e1;
}
form label,form span {
	width: 80px;
	float: left;
	line-height:30px;
}
form label{
	font-weight: bold;
}
form span{
	color: #a0d8ef;
}
form a {
	font-weight: bold;
	background: #a0d8ef;
	cursor: pointer;
	color:#06F;
}
form a:hover {
	background: #eee;
}
form button {
	clear:both;
	margin-left: 100px;
	width: 80px;
	background: #ddd;
	text-align: center;
	line-height: 20px;
	font-weight: bold;
	cursor: pointer;
}
</style>
<body>
<?php
$necessary = array(
    'timestamp' =>     array('text', '时间',    '20121019112816'),
    'merchant_code' => array('text', '商户号',  '10200999'),
    'qid' =>           array('text', '用户id',  '130165900'),
    'mer_order_num' => array('text', '订单号',   date('Ymdhis')),
    'acc_value' =>     array('text', '消费金额', '10'),
    'product_name' =>  array('text', '产品名',   '好产品'),
    'product_desc' =>  array('text', '产品描述', '大家测试。大家测试。大家试。大家测试。'),
    'ext' =>           array('text', '扩展字段', 'this is 360_desktop'),
    'gift_priority' => array('text', '优先用红包', 'N'),
    'notify_url' =>    array('text', '通知url',   'http://hucong.360.cn/internal/dian_cost_notify'),
    'sign' =>          array('text', '签名', '4b8a2fcc59643f27e5a4787aeb4f9ab7'),
);

$submit_url =  'http://'.$_SERVER['SERVER_NAME'].'/account/balancepay';
$html = "<h1>余额消费测试表单</h1>";
$html .= '<form method="post" action="'.$submit_url.'">';
foreach($necessary as $key=>$val){
	$ext = 'sign' == $key?'<a id="update">更新签名</a>':$key;
	$html .= '<label>'.$val[1].': </label><input type="'.$val[0].'" name="'.$key.'" value="'.$val[2].'"/><span>'.$ext."</span>\n";
}
$html .= '<button type="submit">提交</button>';
$html .= '</form>';
echo $html;
?>
</body>
</html>